package com.ymatou.iapi.userservice.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.CheckThirdPartyUserIsNeedBindMobileDtoBean;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymatou.iapi.userservice.parameter.req.BindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.req.UnBindThirdPartyUserReq;
import com.ymatou.iapi.userservice.service.CheckThirdPartyUserIsNeedBindMobileDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.*;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;
import com.ymttest.utils.constant.ThirdPartyType;
/**
*检查第三方账号是否需要绑定手机接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CheckThirdPartyUserIsNeedBindMobileDto{
	private static CheckThirdPartyUserIsNeedBindMobileDtoBean checkthirdpartyuserisneedbindmobiledtoBean;
	private static CheckThirdPartyUserIsNeedBindMobileDtoCall checkthirdpartyuserisneedbindmobiledtoCall;
	private static YmtUsersWapper userWapper;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检查第三方账号是否需要绑定手机接口");
		userWapper = new YmtUsersWapper();
	}

	@Before
	public void caseUp() {
		checkthirdpartyuserisneedbindmobiledtoBean=new CheckThirdPartyUserIsNeedBindMobileDtoBean();
		checkthirdpartyuserisneedbindmobiledtoCall=new CheckThirdPartyUserIsNeedBindMobileDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkthirdpartyuserisneedbindmobiledtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_001() {
		Logger.start(true,"微博账号已经绑定过手机号码，返回不需要绑定");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			JUserCallService.bindThirdPartyUserCall(bd);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(bd.getThirdPartyId());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(bd.getThirdPartyType().toString());
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_002() {
		Logger.start(true,"微信账号已经绑定过手机号码，返回不需要绑定");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(bd.getThirdPartyId());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(bd.getThirdPartyType().toString());
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_003() {
		Logger.start(true,"阿里账号已经绑定过手机号码，返回不需要绑定");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(bd);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(bd.getThirdPartyId());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(bd.getThirdPartyType().toString());
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_004() {
		Logger.start(false,"微博账号未绑定过手机号码，返回需要绑定");
		try {
			String weiboUser = "NotBind_"+TestDataManager.getRandomNum(10);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(weiboUser);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIBO);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals("400", checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_005() {
		Logger.start(false,"微信账号未绑定过手机号码，返回需要绑定");
		try {
			String unionId = "unbindweixin_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(unionId);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIXIN);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals("400", checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_006() {
		Logger.start(false,"阿里账号未绑定过手机号码，返回需要绑定");
		try {
			String weiboUser = "NotBind_"+TestDataManager.getRandomNum(4);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(weiboUser);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.ALI);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals("400", checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_007() {
		Logger.start(false,"未输入第三方账号，检查失败");
		try {
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.ALI);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals("100", checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyIsContains("thirdPartyId can't null", checkthirdpartyuserisneedbindmobiledtoCall.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_008() {
		Logger.start(true,"微博账号绑定再解绑，返回需要绑定");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd=JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			JUserCallService.bindThirdPartyUserCall(bd);
			UnBindThirdPartyUserReq unbind=new UnBindThirdPartyUserReq();
			unbind.setUserId(uid);
			unbind.setThirdPartyType(bd.getThirdPartyType());
			unbind.setThirdPartyId(bd.getThirdPartyId());
			JUserCallService.UnBindThirdPartyUserCall(unbind);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(bd.getThirdPartyId());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(bd.getThirdPartyType().toString());
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals("400", checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_009() {
		Logger.start(true,"微信账号绑定再解绑，返回需要绑定");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd=JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			UnBindThirdPartyUserReq unbind=new UnBindThirdPartyUserReq();
			unbind.setUserId(uid);
			unbind.setThirdPartyId(bd.getThirdPartyId());
			unbind.setThirdPartyType(bd.getThirdPartyType());
			JUserCallService.UnBindThirdPartyUserCall(unbind);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(bd.getThirdPartyId());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(bd.getThirdPartyType().toString());
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals("400", checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_010() {
		Logger.start(true,"alipay账号绑定再解绑，返回需要绑定");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd=JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(bd);
			UnBindThirdPartyUserReq unbind=new UnBindThirdPartyUserReq();
			unbind.setUserId(uid);
			unbind.setThirdPartyId(bd.getThirdPartyId());
			unbind.setThirdPartyType(bd.getThirdPartyType());
			JUserCallService.UnBindThirdPartyUserCall(unbind);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(bd.getThirdPartyId());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(bd.getThirdPartyType().toString());
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals("400", checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}